#include "scanner.h"
#include "parser.h"
#include "opcode.h"
#include <vector>
#include <iostream>

using namespace tinyscript;
using namespace tinyscript::internal;

std::vector<char_t> MakeStringBuffer( const char* str ) {
    std::vector<char_t> ret;
    size_t sz = strlen(str);
    for( size_t i = 0 ; i < sz ; ++i ) {
        ret.push_back(str[i]);
    }
    return ret;
}


// * Testing the parser

int main(int argc, char *argv[])
{

	std::vector<char_t> buf(MakeStringBuffer("{var j = function(someVar,peopleHere){ \
											 var pp = 9*7; \
											 var qq = 7*7%6; \
											 var some = { \
												i = 89; \
												1 = 989; \
												2 = 8*9>=10; }; \
                                                pp = qq *2 + some[1+2+3]; };}"));
    Scanner scanner(buf);
	Parser parser(scanner);

	Parser::ParsingTerminator terminator;
	terminator.AddTerminator(Token::TT_END);
	bool status;
	//Token token = scanner.Advance( Scanner::MODE_IGNORE_WHITESPACE );
	ASNode* tree = parser.ParseChunk(&status);
	if( status ) {
		tree->PrintNode(std::cout);
	} else {
		std::cout<< parser.error_description() <<std::endl;
	}
    std::cout<<"\n\n\nEND"<<std::endl;
	::getchar();
    return -1;
}
